package com.smsc.headend.task.engine;

import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.cache.NodeCache;
import org.apache.curator.framework.recipes.cache.NodeCacheListener;
import org.apache.curator.framework.state.ConnectionState;
import org.apache.curator.framework.state.ConnectionStateListener;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.zookeeper.discovery.watcher.DependencyState;
import org.springframework.cloud.zookeeper.discovery.watcher.DependencyWatcherListener;
import org.springframework.stereotype.Component;

@Slf4j
//@Component
public class ZooConnectionListener implements NodeCacheListener {

//    @Autowired
//    Tr nodeCache;
//
////    @Override
//    public void stateChanged(String dependencyName, DependencyState newState) {
//        log.info("{} change ", dependencyName);
//    }

//    @Override
//    public void process(WatchedEvent watchedEvent) {
//        log.info("{} change ", watchedEvent.getPath());
//    }

//    @Override
//    public void stateChanged(CuratorFramework curatorFramework, ConnectionState connectionState) {
//        log.info("{} change ", connectionState.name());
//    }

    @Override
    public void nodeChanged() throws Exception {
//        System.out.println( ".nodeCache------节点数据发生了改变，发生的路径为：" + nodeCache.getCurrentData().getPath() + ",节点数据发生了改变 ，新的数据为：" + new String(nodeCache.getCurrentData().getData()) + "\n===========================\n");
    }
}
